const state = {
  username: null,
};

const mutations = {
  SET_USERNAME(state, username) {
    state.username = username;

  },
  CLEAR_USERNAME(state) {
    state.username = null;
  },
};


// state是存放数据的，mutations是同步更新数据 (便于监测数据的变化, 更新视图等, 方便于调试工具查看变化)，

// actions则负责进行异步操作
const actions = {
  setUsername({ commit }, username) {
    commit('SET_USERNAME', username);
  },
  clearUsername({ commit }) {
    commit('CLEAR_USERNAME');
  },
};

const getters = {
  username: (state) => state.username,
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters,
};
